﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FriendsNearby.Services.Entities;
using FriendsNearby.Properties;
using System.Globalization;
using InSTEDD.Labs.Geo;

namespace FriendsNearby
{
    public class PersonNearbyPresentation
    {
        // TODO find a better and complete solution.
        public static string EncodeJavaScriptString(string str)
        {
            return str.Replace("\"", "\\\"");
        }

		public static string GetDistanceString(int distanceInKm)
		{
			return DistanceHelper.GetDistanceString((double)distanceInKm);
		}

        public static string GetDistanceString(double? distanceInKm)
        {
            return DistanceHelper.GetDistanceString(distanceInKm);
        }

        /// <summary>
        /// Generate HTML code with display name of the person and 
        /// link to person profile if correspond.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="person"></param>
        public static void WriteUserNameHtml(HtmlTextWriter output, PersonNearby person)
        {
            if (person.IsHidden)
            {
                output.RenderBeginTag(HtmlTextWriterTag.B);
                output.WriteEncodedText(person.DisplayName);
                output.RenderEndTag();
            }
            else
            {
                output.AddAttribute(HtmlTextWriterAttribute.Href, "http://www.facebook.com/profile.php?id=" + person.FacebookUserID);
                output.AddAttribute(HtmlTextWriterAttribute.Target, "_blank");
                output.RenderBeginTag(HtmlTextWriterTag.A);
                output.WriteEncodedText(person.DisplayName);
                output.RenderEndTag();
            }
        }
    }
}
